package com.mezo.athena.web.controller.system;

import com.mezo.athena.common.annotation.Log;
import com.mezo.athena.common.core.controller.BaseController;
import com.mezo.athena.common.core.domain.AjaxResult;
import com.mezo.athena.common.core.page.TableDataInfo;
import com.mezo.athena.common.enums.BusinessType;
import com.mezo.athena.common.utils.poi.ExcelUtil;
import com.mezo.athena.system.domain.RyBrand;
import com.mezo.athena.system.service.IRyBrandService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 品牌Controller
 * 
 * @author athena
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/system/brand")
public class RyBrandController extends BaseController
{
    @Autowired
    private IRyBrandService ryBrandService;

    /**
     * 查询品牌列表
     */
    @PreAuthorize("@ss.hasPermi('system:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(RyBrand ryBrand)
    {
        startPage();
        List<RyBrand> list = ryBrandService.selectRyBrandList(ryBrand);
        return getDataTable(list);
    }

    /**
     * 导出品牌列表
     */
    @PreAuthorize("@ss.hasPermi('system:brand:export')")
    @Log(title = "品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RyBrand ryBrand)
    {
        List<RyBrand> list = ryBrandService.selectRyBrandList(ryBrand);
        ExcelUtil<RyBrand> util = new ExcelUtil<RyBrand>(RyBrand.class);
        util.exportExcel(response, list, "品牌数据");
    }

    /**
     * 获取品牌详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:brand:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ryBrandService.selectRyBrandById(id));
    }

    /**
     * 新增品牌
     */
    @PreAuthorize("@ss.hasPermi('system:brand:add')")
    @Log(title = "品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RyBrand ryBrand)
    {
        return toAjax(ryBrandService.insertRyBrand(ryBrand));
    }

    /**
     * 修改品牌
     */
    @PreAuthorize("@ss.hasPermi('system:brand:edit')")
    @Log(title = "品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RyBrand ryBrand)
    {
        return toAjax(ryBrandService.updateRyBrand(ryBrand));
    }

    /**
     * 删除品牌
     */
    @PreAuthorize("@ss.hasPermi('system:brand:remove')")
    @Log(title = "品牌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ryBrandService.deleteRyBrandByIds(ids));
    }
}
